package com.neusoft.dibuy.th;

public class MyWait {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("--------------------");
        MyThread1 myThread1 = new MyThread1();
        myThread1.start();
        new MyThread2().start();
        myThread1.join();
        System.out.println("MyWait.main");
    }
}
class MyThread2 extends Thread{
    public void run() {
        synchronized("abd") {
        try {
            Thread.sleep(20000);
           "abd".notifyAll();
            System.out.println("MyThread2.run --- > notifyAll");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        }
    }
}
class MyThread1 extends Thread{
    public void run() {
        synchronized("abd") {
            for (int i = 0; i < 10; i++) {
                System.out.println("thread1 :" + i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (i == 5) {
                    try {
                        "abd".wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
